﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace orz.mouxianyu.Extensions
{
    public static class SqlClientExtensions
    {
        /// <summary>
        /// 配置 SqlConnection client Startup 辅助类
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddSqlClient(this IServiceCollection services, IConfiguration Configuration)
        {

            /*
           *  注入 SqlConnection
           */
            services.AddScoped<SqlConnection>((ctc) =>
            {
                string connectionString = Configuration["MSSQLConnection:SqlConnectionString"]; //@"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=IdentityServer4;Integrated Security=True";
                SqlConnection con = new SqlConnection(connectionString);
                return con;
            });


            return services;
        }
    }
}
